package com.htxs.common.action;

import com.htxs.common.util.SplitPage;
import com.opensymphony.xwork2.ActionSupport;

public class PageAction extends ActionSupport implements PageAware {

	protected Integer dataCount;
	
	protected SplitPage pageInfo=new SplitPage();

	public Integer getDataCount() {
		return dataCount;
	}

	public void setDataCount(Integer dataCount) {
		this.dataCount = dataCount;
	}

	public void setLimit(Integer limit) {
		validPage();
		this.pageInfo.setLimit(limit);
	}

	public void setStart(Integer start) {
		validPage();
		this.pageInfo.setStart(start);
	}

	public void setDir(String dir) {
		validPage();
		this.pageInfo.setDir(dir);
	}

	public void setSort(String sort) {
		validPage();
		this.pageInfo.setSort(propertyConvertToField(sort));
	}
	
	private void validPage(){
		if(this.pageInfo==null)
			this.pageInfo=new SplitPage();
	}
	protected String propertyConvertToField(String prop){
		if((prop==null) || ("".equalsIgnoreCase(prop)))
			return "";
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<prop.length();++i){
			char c=prop.charAt(i);
			if(c<='Z')
				sb.append("_");
			sb.append(c);
		}
		return sb.toString().toUpperCase();
	}

	public SplitPage getPageInfo() {
		return pageInfo;
	}

	public void setPageInfo(SplitPage pageInfo) {
		this.pageInfo = pageInfo;
	}
}
